# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=faker
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=4.0.3
pkgrel=1
pkgdesc="Faker generates fake data for you (mingw-w64)"
arch=('any')
url="https://faker.readthedocs.io/en/master/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-text-unidecode")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-ukpostcodeparser"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-email-validator")
install=${_realname}3-${CARCH}.install
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/joke2k/faker/archive/v${pkgver}.tar.gz")
sha512sums=('08d7a4fc3a65f4f31467e0aa91525ce92042ef7e471992a63c3fef2efa14ab894bda1f0fa1e6b651f78ceadee7c3683079001db904147739628457a44adef615')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done
}
